package com.qk.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.Map;

/**
 *
 * @author lyl
 * @created 2025/10/11 10:33
 * @description
 *
 */
@Slf4j
public class JwtUtils {

    // 秘钥
    private static final String SECRET_KEY = "cWluZ2tl";
    // 令牌有效期（12小时）
    private static final long EXPIRATION_TIME =  24 * 60 * 60 * 1000;

    public static String generateToken(Map<String, Object> claims) {
        return Jwts.builder()
                .setClaims(claims)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
                .signWith(SignatureAlgorithm.HS256, SECRET_KEY)
                .compact();
    }

    public static Claims parseToken(String token) {
        return  Jwts.parser()
                .setSigningKey(SECRET_KEY)
                .parseClaimsJws(token)
                .getBody();
    }
}
